// 引入消息提示组件import message from 'xxx'
// import useStore from '@/store';
import axios, { type Method } from 'axios';
const baseURL = import.meta.env.VITE_BASE_URL; 
const instance = axios.create({ baseURL, timeout: 50000 });// 创建 axios 实例

instance.interceptors.request.use(
	(config) => {
		// const { member } = useStore();
		// const token = member.member.profile.token;
		// if (token && config.headers) config.headers.Authorization = `Bearer ${token}`;
		return config;
	},
	(error) => {
		// message.error(`请求错误：${error.message}`);
		return Promise.reject(error);
	}
);

instance.interceptors.response.use(
	(response) => response,
	(error) => {
		if (!axios.isAxiosError(error)) return;
		// message.error(error.response?.data?.message || '网络错误!');
		new Error('请求报错：',error);
		return Promise.reject(error);
	}
);

export type ResponseData<T = any> = { data: { code: string; msg: string; result: T } };

export const http = <T>(method: Method, url: string, submitData?: unknown) => {
	return instance.request<T, ResponseData<T>>({
		url,
		method,
		[method.toUpperCase() === 'GET' ? 'params' : 'data']: submitData,
	});
};
export default instance;//不推荐直接使用

// 使用方式：
// http('GET','/api/user/info')
// http('post', '/api/user/info', { name: '123' })
